package day_2022_7_to_8.day48;

import java.util.Stack;

/**
 * @author haomin
 * @date 2022/08/31 14:22
 **/
public class Day46_1_Num946_ValidateStackSequences {
    class Solution {
        public boolean validateStackSequences(int[] pushed, int[] popped) {
            Stack<Integer> stack = new Stack<>();
            int j = 0;
            for(int i = 0; i < pushed.length; ++i){
                stack.push(pushed[i]);
                while(!stack.isEmpty() && stack.peek() == popped[j]){
                    j++;
                    stack.pop();
                }
            }
            return stack.isEmpty();
        }
    }
}